//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;

namespace OpenLS.Chart
{
    public class ManualLayout : IOfficeXmlSerializable
    {
        private ExtensionElement _extension;
        private double _h;


        private LayoutTarget _layoutTarget;
        private double _w;
        private double _x;

        private LayoutMode _xMode;
        private double _y;

        private LayoutMode _yMode;

        public ExtensionElement Extension
        {
            get { return _extension; }
            set { _extension = value; }
        }

        public LayoutTarget LayoutTarget
        {
            get { return _layoutTarget; }
            set { _layoutTarget = value; }
        }

        public LayoutMode XMode
        {
            get { return _xMode; }
            set { _xMode = value; }
        }

        public LayoutMode YMode
        {
            get { return _yMode; }
            set { _yMode = value; }
        }

        public double X
        {
            get { return _x; }
            set { _x = value; }
        }

        public double Y
        {
            get { return _y; }
            set { _y = value; }
        }

        public double Width
        {
            get { return _w; }
            set { _w = value; }
        }

        public double Height
        {
            get { return _h; }
            set { _h = value; }
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("manualLayout"))
            {
                _layoutTarget =
                    c.ReadOptionalElementEnumAttribute("layoutTarget", "val", LayoutTarget.Outer,
                                                                     LayoutTarget.Outer); //\\ defaultOK?
                XMode =
                    c.ReadOptionalElementEnumAttribute("xMode", "val", LayoutMode.Factor, LayoutMode.Factor);
                YMode = c.ReadOptionalElementEnumAttribute("yMode", "val", LayoutMode.Factor, LayoutMode.Factor);
                WidthMode = c.ReadOptionalElementEnumAttribute("wMode", "val", LayoutMode.Factor, LayoutMode.Factor);
                HeightMode = c.ReadOptionalElementEnumAttribute("hMode", "val", LayoutMode.Factor, LayoutMode.Factor);
                X = c.ReadOptionalElementDoubleAttribute("x", "val", 0);
                Y = c.ReadOptionalElementDoubleAttribute("y", "val", 0);
                Width = c.ReadOptionalElementDoubleAttribute("w", "val", 0);
                Height = c.ReadOptionalElementDoubleAttribute("h", "val", 0);
                Extension = c.ReadOptionalElement<ExtensionElement>("extLst");
            }
        }

        protected LayoutMode HeightMode { get; set; }

        protected LayoutMode WidthMode { get; set; }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("manualLayout"))
            {
                c.WriteOptionalElementEnumAttribute("layoutTarget", "val", LayoutTarget,
                                                                  LayoutTarget.Outer, LayoutTarget.Outer);
                    //\\ defaultOK?
                c.WriteOptionalElementEnumAttribute("xMode", "val", XMode, LayoutMode.Factor,
                                                                LayoutMode.Factor);
                c.WriteOptionalElementEnumAttribute("yMode", "val", YMode, LayoutMode.Factor, LayoutMode.Factor);
                c.WriteOptionalElementEnumAttribute("wMode", "val", WidthMode, LayoutMode.Factor, LayoutMode.Factor);
                c.WriteOptionalElementEnumAttribute("hMode", "val", HeightMode, LayoutMode.Factor, LayoutMode.Factor);
                c.WriteOptionalElementDoubleAttribute("x", "val", X, 0);
                c.WriteOptionalElementDoubleAttribute("y", "val", Y, 0);
                c.WriteOptionalElementDoubleAttribute("w", "val", Width, 0);
                c.WriteOptionalElementDoubleAttribute("h", "val", Height, 0);
                c.WriteOptionalElement(Extension);
            }
        }

        #endregion
    }
}